#作业一、三种时间模式的转换
#1、datetime.datetime->str
import datetime
from datetime import timedelta
now = datetime.datetime.now(tz=None)   #获取当前时间
now = now.strftime("%Y-%m-%d %H:%M:%S")   #时间格式转换  datetime.datetime->str
print(now)

#2、str->datetime.datetime
now = datetime.datetime.strptime(now, "%Y-%m-%d %H:%M:%S")   #时间格式转换  str->datetime.datetime
print(now.__repr__())

#3、datetime.datetime->timestamp
now_1 = datetime.datetime.now(tz=None)   #获取当前时间
now_1 = now_1.timestamp()   #时间格式转换   datetime.datetime->timestamp
print(now_1)

#4、timestamp->datetime.datetime
now_1 = datetime.datetime.fromtimestamp(now_1, tz=None)   #时间格式转换   timestamp->datetime.datetime
print(now_1.__repr__())

#作业二、封装一个函数get_date(day_delta), 如果传入的是-1 , 输出就是字符串日期2020-01-02

def get_date(day_delta):
    now_2 = datetime.datetime.now(tz=None)  # 获取当前时间
    now_2 = now_2 + timedelta(days=day_delta)
    now_2 = now_2.strftime("%Y-%m-%d")  # 转换时间格式
    return now_2

n = int(input('请输入一个整数：'))
date = get_date(n)
print(date)